{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "49438f3e",
   "metadata": {},
   "source": [
    "## 1.1优化百度ASR接口"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6c87e965",
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'asr' from 'bdasr' (C:\\Users\\枝枝糖~\\Documents\\API\\11\\bdasr.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-25-4a1f52e75d28>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mbdasr\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mfetch_token\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0masr\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m: cannot import name 'asr' from 'bdasr' (C:\\Users\\枝枝糖~\\Documents\\API\\11\\bdasr.py)"
     ]
    }
   ],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "56dae6e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 以下为asr代码优化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3a1bf82c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "49faa9ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# jiezhi : asr\n",
    "API_KEY = 'dzWPEA9d3AGWzzgUE9NWgDZn'\n",
    "SECRET_KEY = '1Q6PA4o6wARvT7BGiLji4XFseCDRD3MP'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3ebad63b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.43449bf013b73ac54a3b70726ed34e26.2592000.1655292420.282335-26192424'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jie_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "jie_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3cb7f139",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "\n",
    "r = speech_recognition.Recognizer()\n",
    "\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47fcff90",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
